import createRouteMap from './creat-route-map'
import createRoute from './util/route'
export default function createMatcher(routes) {
  const {
    pathList,
    pathMap
  } = createRouteMap(routes)
  // console.log(pathList);
  // console.log("pathMap:"+pathMap);

  function match(path) {
    const record = pathMap[path]
    if (record) {
      return createRoute(record,path)
    }
    return createRoute(null,path)
  }

  function addRoutes(routes) {
    createRouteMap(routes, pathList, pathMap)
  }
  return {
    match,
    addRoutes
  }
}